<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .fail_box {
        	display: none;
        }
        .success_box{
            display: none;
        }
        .main {
        	height: 145px;
        	background-color: #fff;
        	text-align: center;
        	display: -webkit-box;
        	-webkit-box-align: center;
        	-webkit-box-pack: center;
        }
        .main .result_box .success_icon {
        	width: 54px;
        }
        .main .result_box .fail_icon {
        	width: 36px;
        }
        .main .result_box p {
        	font-size: 16px;
        	color: #333;
        	margin-top: 15px;
        }
        .btn_box {
        	padding: 20px 15px 0;
        }
        .fail_btn_box {
        	padding: 25px 15px 0;
        }
        .btn_box .btn {
        	height: 40px;
        	line-height: 40px;
        	color: #fff;
        	text-align: center;
        	border-radius: 5px;
        	background-color: #e62442;
        	font-size: 16px;
        }
        .order_info {
        	padding: 15px;
        	background-color: #fff;
        	margin-top: 6px;
        }
        .order_info .title_box {
        	display: -webkit-box;
        	display: -webkit-flex;
        	margin-bottom: 15px;
        }
        .order_info .title_box .title_boxl {
			width: 0;
			flex: 1;
			-webkit-flex: 1;
			box-flex: 1;
			-webkit-box-flex: 1;
        }
        .order_info .title_box .title_boxl .title_p {
        	font-size: 15px;
        	color: #333;
        	margin-bottom: 10px;
        }
        .order_info .title_box .title_boxl .time {
        	font-size: 12px;
        	color: #999;
        }
        .order_info .title_box .title_boxr {
			color: #16be5d;
			font-size: 13px;
			padding-top: 2px;
			padding-left: 5px;
        }
        .order_info .info_box {
        	font-size: 13px;
        	color: #333;
        }
        .order_info .info_box span {
        	color: #e62442;
        }
        .order_info .info_box .info {
        	padding-bottom: 10px;
        }
        .order_info .info_box .info span {
            margin-left: 8px;
        }
		.order_info .info_box .address {
        	padding-bottom: 17px;
        }
        .order_info .goods_info {
        	display: -webkit-box;
        	display: -webkit-flex;
        	align-items: center;
        }
        .order_info .goods_info .goods_infol {
        	width: 0;
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	font-size: 12px;
        	color: #999;
        }
        .order_info .goods_info .goods_infor {
        	font-size: 17px;
        	color: #e62442;
        	padding-left: 5px;
        }
        .order_info .info_box .info .username{
            color: #333;
            margin-left: 0;
        }
    </style>
</head>
<body>
	<div class="success_box">
		<div class="main">
    		<div class="result_box">
	    		<img class="success_icon" src="../image/success.png">
	    		<p>客户身份验证成功</p>
    		</div>
    	</div>
    	<div class="order_info">
    		<div class="title_box">
    			<div class="title_boxl">
    				<div class="title_p">订单信息</div>
    				<div class="time">&nbsp;&nbsp;</div>
    			</div>
    			<div class="title_boxr">配送中</div>
    		</div>
    		<div class="info_box">
    			<div class="info"><span class="username">&nbsp;</span><span class="aaaaaa">&nbsp;</span></div>
    			<div class="address">&nbsp;</div>
    		</div>
    		<div class="goods_info">
    			<div class="goods_infol order_detail">&nbsp;</div>
    			<div class="goods_infor">RM<span class="total_price"></span></div>
    		</div>
    	</div>
    	<div class="btn_box">
    		<div class="btn" tapmode onclick="confirmOrderDelivery();">确认送达</div>
    	</div>
	</div>
    <div class="fail_box">
    	<div class="main">
    		<div class="result_box">
	    		<img class="fail_icon" src="../image/prompt.png">
	    		<p>客户身份验证失败</p>
    		</div>
    	</div>
    	<div class="btn_box fail_btn_box">
    		<div class="btn" tapmode onclick="api.closeWin();">返回</div>
    	</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    

    apiready = function(){
        staffData = $api.getStorage('staff_data');
        isSuccess = api.pageParam.isSuccess;
        orderId = api.pageParam.orderId;
        uid = api.pageParam.uid;
        getInitData(isSuccess,orderId,uid);

        api.sendEvent({
            name: 'changeNeedOpen',
        });
        
    };


    function confirmOrderDelivery () {
        api.ajax({
            url: rootPath + '/api/staff/confirm_order_delivery',
            method: 'post',
            data: {
                values: { 
                    staff_id: staffData.id,
                    staff_token: staffData.token,
                    order_id: orderId,
                    uid: uid,
                },
            }
        }, function(ret, err) {
            if (ret) {
                if(ret.status == 200){
                    toast('确认成功');
                    api.sendEvent({
                        name: 'staffScanUserOrderSuccess',
                        extra: {
                            oid: ret.data.oid, 
                        }
                    });
                    setTimeout(function(){
                        api.closeToWin({
                            name: 'root'
                        });
                    },500);
                }
            }
        });
    };

    function getInitData () {
        if(isSuccess == 1){
            api.ajax({
                url: rootPath + '/api/staff/get_scan_order_detail',
                method: 'post',
                data: {
                    values: { 
                        staff_id: staffData.id,
                        staff_token: staffData.token,
                        order_id: orderId,
                        uid: uid,
                    },
                }
            }, function(ret, err) {
                if (ret) {
                    if(ret.status == 200){
                        $(".time").html(ret.data.create_time);
                        $(".username").html(ret.data.username);
                        $(".aaaaaa").html(ret.data.tel);
                        $(".address").html(ret.data.area_name2 + ret.data.address_detail);
                        $(".total_price").html(ret.data.must_pay);
                        if(ret.data.order_detail){
                            var i = 0;
                            var order_detail = '';
                            $.each(ret.data.order_detail, function(k, v) {
                                if(k == 0){
                                    order_detail = v;
                                }else if(k == 1){
                                    order_detail = order_detail+'、'+v;
                                }else if(k == 2){
                                    order_detail = order_detail+'等';
                                }
                                i++;
                            });
                            $(".order_detail").html(order_detail+i+'样菜品');
                        }
                    }
                } else {
                    // alert(JSON.stringify(err));
                }
            });
            $(".success_box").show();
        }else{
            $(".fail_box").show();

        }
    };


</script>
</html>

